﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using service;
using model;

namespace BHTT.Baiviet.subview
{
    public partial class Themmoibaiviet : System.Web.UI.Page
    {
        private Loaibaiviet l = new Loaibaiviet();
        private BaivietService baivietService = new BaivietService();
        protected void Page_Load(object sender, EventArgs e)
        {
            string s = Request.QueryString["Loai"];
            l = new LoaibaivietService().GetBaivietaByName(s);
        }

        // Chỉ định loại file
        private bool checkFileType(string FileName)
        {
            string ext = Path.GetExtension(FileName);

            if (ext.Equals(".png") || ext.Equals(".jpg") || ext.Equals(".jpeg") || ext.Equals(".gif"))
            {
                return true;
            }
            else
            {
                return false;
            }

        }

        // Chỉ định kích thước file
        private bool checkFileSize(HttpPostedFile pf)
        {
            if (pf.ContentLength < 65536)
                return true;
            else
            {
                return false;
            }
        }

        // Chỉ định kích thước ảnh ( nhỏ hơn 100px x 100px )
        private bool checkImageSize()
        {
            using (System.Drawing.Image myImage = System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream))
            {
                if (myImage.Height <= 150 && myImage.Width <= 150)
                    return true;
                else
                    return false;
            }

        }

        protected void btnThemmoi_Click(object sender, EventArgs e)
        {
            BaivietModel bv = new BaivietModel();
             bv.IDLoaibaiviet = l.ID;
            bv.Mabaiviet = txtMabaiviet.Text;
            bv.Tenbaiviet = txtTenbaiviet.Text;
            bv.Shortcut = txtShortcut.Text;
            bv.Noidung = txtNoidung.Content;
            bv.Nguoiviet = txtNguoiviet.Text;
            bv.Ngayviet = DateTime.Now;
            FileUpload1.SaveAs(Server.MapPath("~/Image/") + FileUpload1.FileName);
            bv.Anhdaidien = "../Image/" + FileUpload1.FileName;

            string s = baivietService.themmoiBaiviet(bv);
        }
    }
}